clear all
set printcolor gs1, permanently
set more off
cap log close
program drop _all
set matsize 11000, permanently

use "INTERMEDIATE/product_RMS_def10_firm_sampleE_06_15.dta", clear
gen logrevenue  = log(revenue)
egen fe=group(module quarter)
qui tab cohort, gen(cohort_d)
 
gen maxAge3 = maxAge if maxAge<=28 & (censored=="not censored" )
replace maxAge3 = 99 if maxAge>28 &  (censored=="not censored" |  censored=="right censored")
replace maxAge3 = 999 if (censored=="left censored" | censored=="left censored & right censored")
gen age_2=age if maxAge3<=99 
replace age_2=1 if maxAge3==999

* Regression
areg logrevenue i.age_2#i.maxAge3 if (cohort>=1 & cohort<=35) & age_2<maxAge & age_2>=1 &age_2<=32 , absorb(fe)
matrix results=[e(b)',vecdiag(e(V))']
svmat results
rename results1 coef_
rename results2 se_
keep coef_ se_
seq MaxAge, f(1) t(29)
seq age, f(1) t(32) b(29)
gen n = _n
drop if n>=928
drop n
reshape wide coef_ se_, i(age) j(MaxAge)

foreach num of numlist 1(1)17 {
gen coef_`num'_u = coef_`num' + 1.96*sqrt(se_`num')
gen coef_`num'_l = coef_`num' - 1.96*sqrt(se_`num')
}


#delimit;
twoway 
(scatter coef_1 age if age<=1, msize(small)  color(black) )  
(line coef_2 age if age<=2, lwidth()  color(red) lpattern(shortdash) )  
(line coef_3 age if age<=3, lwidth() lcolor(pink))  
(line coef_4 age if age<=4, lwidth() lcolor(orange) lpattern(shortdash))  
(line coef_5 age if age<=5, lwidth() lcolor(navy))  
(line coef_6 age if age<=6, lwidth() lcolor(maroon) lpattern(shortdash))  
(line coef_7 age if age<=7, lwidth() lcolor(green))  
(line coef_8 age if age<=8, lwidth() lcolor(blue) lpattern(shortdash))  
(line coef_9 age if age<=9, lwidth() lcolor(red)) 
(line coef_10 age if age<=10, lwidth() lcolor(pink) lpattern(shortdash))  
(line coef_11 age if age<=11, lwidth() lcolor(orange))  
(line coef_12 age if age<=12, lwidth() lcolor(navy) lpattern(shortdash))  
(line coef_13 age if age<=13, lwidth() lcolor(maroon))  
(line coef_14 age if age<=14, lwidth() lcolor(green) lpattern(shortdash))  
(line coef_15 age if age<=15, lwidth() lcolor(blue))  
(line coef_16 age if age<=16, lwidth()  color(red) lpattern(shortdash) )  
(line coef_17 age if age<=17, lwidth() lcolor(pink))  
(line coef_18 age if age<=18, lwidth() lcolor(orange) lpattern(shortdash))  
(line coef_19 age if age<=19, lwidth() lcolor(navy))  
(line coef_20 age if age<=20, lwidth() lcolor(maroon) lpattern(shortdash))  
(line coef_21 age if age<=21, lwidth() lcolor(green))  
(line coef_22 age if age<=22, lwidth() lcolor(blue) lpattern(shortdash))  
(line coef_23 age if age<=23, lwidth() lcolor(red))  
(line coef_24 age if age<=24, lwidth() lcolor(pink) lpattern(shortdash))  
(line coef_25 age if age<=25, lwidth() lcolor(orange))  
(line coef_26 age if age<=26, lwidth() lcolor(navy) lpattern(shortdash))  
(line coef_27 age if age<=27, lwidth() lcolor(maroon))  
, ytitle("Estimated Sales (log scale)" " " " " " ") xtitle("Age (quarters)") xlabel(4[4]28) 
title("") ylabel(-4(2)3) 
leg(on row(3) order(1 "2" 2 "3" 3 "4" 4 "5" 5 "6" 6 "7" 7 "8" 8 "9" 9 "10" 10 "11" 11 "12" 12 "13" 13 "14" 14 "15" 15 "16" 16 "17" 17 "18" 18 "19" 19 "20" 20 "21" 21 "22" 22 "23" 23 "24" 24 "25" 25 "26" 26 "27" 27 "28")) 
graphregion(color(white)) plotregion(fcolor(white)) legend(region(lcolor(white))) note("");	
#delimit cr 
graph export "OUTPUT/Figure3.eps", replace


